<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>hashCode演示</title>
    <script src="js/echarts.common.min.js"></script>
</head>
<body>
<p>质数为：<input type="text" value="31" id="n"><input type="button" value="修改" onclick="updateChart()">
    冲突单词共<span id="collide"></span>个 冲突率为：<span id="ratio"></span>
</p>
<div id="main" style="width: 100%;height:400px;"></div>
<script type="text/javascript">


function updateChart() {
    var n = document.getElementById("n").value;

    fetch("/hashCode?n="+n).then(response=>{
        return response.json();
    }).then(json=>{
        var data = json.data;
        document.getElementById("ratio").innerText=json.ratio;
        document.getElementById("collide").innerText=json.collide;
        var xdata = [];
        var ydata = [];
        for(var d in data) {
            xdata.push(d-0);
        }
        xdata.sort((a,b)=>a-b);
        for(var i=0; i<xdata.length;i++){
            ydata.push(data[xdata[i]]);
        }
        console.log(xdata);
        console.log(ydata);
        var option = {
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: xdata
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                data: ydata,
                type: 'line',
                areaStyle: {}
            }]
        };
        myChart.setOption(option);
    });
}

var myChart = echarts.init(document.getElementById('main'));
updateChart();


</script>
</body>
</html>